﻿@using ETD.Common.Extension;
@using ETD.WebOrganization.Libs.Helper;
@using ETD.WinClient.Config;
@using ETD.Domain.EnumModels;
@using ETD.Domain.WebModels;
@using ETD.Common;
@model ETD.WebOrganization.Areas.Web.Models.CurrentSecurityTableModel
@{
    ViewBag.Title = "安检表";
}
@{
//var securityCheckItemList = Model.SecurityCheckItemList.Where(x => x.CheckResultStatusID == (int)ECheckResultStatus.WaitCheck).ToList();
//var securityCheckItemQualifiedList = Model.SecurityCheckItemList.Where(x => x.CheckResultStatusID == (int)ECheckResultStatus.Qualified).ToList();
//var securityCheckItemUnqualifiedList = Model.SecurityCheckItemList.Where(x => x.CheckResultStatusID == (int)ECheckResultStatus.Unqualified).ToList();
}
<style>
    .weui-center {
        text-align: center;
    }

    .WpSecurityTableLink {
    }
</style>
<div class="weui-panel">
    <div class="weui-panel__hd">当前安检表</div>
    @if (Model.CurrentUIWpSecurityTable != null)
    {
        <div class="weui-panel__bd">
            <div class="weui-media-box weui-media-box_small-appmsg">
                <div class="weui-cells">

                    <a class="weui-cell weui-cell_access WpSecurityTableLink" href="javascript:;">
                        <div class="weui-cell__hd"><img src="" alt="" style="width:20px;margin-right:5px;display:block"></div>
                        <div class="weui-cell__bd weui-cell_primary">
                            <p>@Model.CurrentUIWpSecurityTable.Name</p>
                        </div>
                        <span class="weui-cell__ft"></span>
                    </a>

                </div>
            </div>
        </div>
    }
    else
    {
        <div class="weui-panel__hd weui-center">无安检表</div>
    }

    <div class="weui-panel__hd">最近使用安检表</div>
    @if (Model.UserUsedSecurityTableList.Count > 0)
    {
        <div class="weui-panel__bd">
            <div class="weui-media-box weui-media-box_small-appmsg">
                <div class="weui-cells">
                    @for (int index = 0; index < Model.UserUsedSecurityTableList.Count; index++)
                    {
                        var securityCheckItem = Model.UserUsedSecurityTableList[index];
                        <a class="weui-cell weui-cell_access WpSecurityTableLink" href="javascript:;">
                            <div class="weui-cell__hd"><img src="" alt="" style="width:20px;margin-right:5px;display:block"></div>
                            <div class="weui-cell__bd weui-cell_primary">
                                <p>@securityCheckItem.Name</p>
                            </div>
                            <span class="weui-cell__ft"></span>
                        </a>
                    }
                </div>
            </div>
        </div>
    }
    else
    {
        <div class="weui-panel__hd weui-center">无安检表</div>
    }

    <div class="weui-panel__hd">其他安检表</div>
    @if (Model.OtherSecurityTableList.Count > 0)
    {
        <div class="weui-panel__bd">
            <div class="weui-media-box weui-media-box_small-appmsg">
                <div class="weui-cells">

                    @for (int index = 0; index < Model.OtherSecurityTableList.Count; index++)
                    {
                        var otherSecurityTable = Model.OtherSecurityTableList[index];
                        <a class="weui-cell weui-cell_access WpSecurityTableLink" href="javascript:;" data-name="@otherSecurityTable.Name" data-wpsecuritytableid="@otherSecurityTable.WpSecurityTableID">
                            <div class="weui-cell__hd"><img src="" alt="" style="width:20px;margin-right:5px;display:block"></div>
                            <div class="weui-cell__bd weui-cell_primary">
                                <p>@otherSecurityTable.Name</p>
                            </div>
                            <span class="weui-cell__ft"></span>
                        </a>
                    }

                </div>
            </div>
        </div>
    }
    else
    {
        <div class="weui-panel__hd weui-center">无安检表</div>
    }
</div>

@section ScriptSection{
    <script>
        $(function () { CurrentSecurityTableObject.Init(); });
        var CurrentSecurityTableObject = {
            Init: function () {
                $(".WpSecurityTableLink").click(CurrentSecurityTableObject.OnWpSecurityTableLinkClick);
            },
            OnWpSecurityTableLinkClick: function () {
                $this = $(this);
                console.log($this.data("name"));
                console.log($this.data("wpsecuritytableid"));
                CurrentSecurityTableObject.SelectedWpSecurityTableLink = {
                    "Name": $this.data("name"),
                    "WpSecurityTableID": $this.data("wpsecuritytableid")
                };
                CurrentSecurityTableObject.OpenActionMenu();
            },
            SelectedWpSecurityTableLink: null,
            OpenActionMenu: function () {
                $.actions({
                    title: "选择操作",
                    onClose: function () {
                        console.log("close");
                    },
                    actions: [
                      {
                          text: "切换到>>" + CurrentSecurityTableObject.SelectedWpSecurityTableLink.Name,
                          className: "color-primary",
                          onClick: function () {
                              CurrentSecurityTableObject.OnActionMenuSwitchClick();
                          }
                      },
                      //{
                      //    text: "删除",
                      //    className: 'color-danger',
                      //    onClick: function() {
                      //        $.alert("你选择了“删除”");
                      //    }
                      //}
                    ]
                });
            },
            OnActionMenuSwitchClick: function () {
                var paras = {};
                paras.WpSecurityTableID = CurrentSecurityTableObject.SelectedWpSecurityTableLink.WpSecurityTableID;
                ajaxPost("@Url.Action("SwitchToWpSecurityTable", "SecurityTable")", paras, function (data) {
                    console.log(data);
                    if (data.Status) {
                        $.toast("操作完成!");
                        setTimeout(function () {
                            window.location.reload(); }, 1000);
                    } else {
                        $.toast(data.Info, "forbidden");
                    }
                });

            }

        };

    </script>
}